const fs = require('fs').promises
var images = require("images");
const compress_images = require("compress-images");

// const fileHelper = {
//   readFile: (path) => {
//     return fs.readFile(path, { encoding: 'utf8'})
//   },
//   writeFile: (path, content) => {
//     return fs.writeFile(path, content, { encoding: 'utf8'})
//   },
//   renameFile: (path, newPath) => {
//     return fs.rename(path, newPath)
//   },
//   deleteFile: (path) => {
//     return fs.unlink(path)
//   },
//   imageMin:(path = 'D:\11.jpg') =>{
    
//   }
// }
let imageMin = () =>{
  // https://www.npmjs.com/package/compress-images
    // //支持png/jpeg/gif三种格式输入。目前支持设置JPG输出图像质量   妈的不支持jpg
    debugger;
    console.log('21212121',__dirname);
    if(!path){
      return;
    }
    let p = __dirname +'\\22.png';
    console.log('21212121',p);
    let photo = images(p);
    images(p).save(p, {
        quality : 50                    //保存图片到文件,图片质量为50
    });
}
let min2 = ()=>{
    // 这个路径很有意思，很有意思
    // 'D:\\personal\\electron-demo\\electron-react-start/'  ok
    // 'D:\\personal/'  ok
 // let   INPUT_path_to_your_images = 'D:/personal/electron-demo/electron-react-start/imgText/**/*.{jpg,JPG,jpeg,JPEG,png,svg,gif}';  是ok的
 let   INPUT_path_to_your_images = 'imgText/**/*.{jpg,JPG,jpeg,JPEG,png,svg,gif}';// 相对路径也是ok的
 let OUTPUT_path = __dirname +'/';
 console.log('21212121',__dirname);

compress_images(INPUT_path_to_your_images, OUTPUT_path, { compress_force: false, statistic: true, autoupdate: true }, false,
                { jpg: { engine: "mozjpeg", command: ["-quality", "60"] } },
                { png: { engine: "pngquant", command: ["--quality=20-50", "-o"] } },
                { svg: { engine: "svgo", command: "--multipass" } },
                { gif: { engine: "gifsicle", command: ["--colors", "64", "--use-col=web"] } },
  function (error, completed, statistic) {
    console.log("-------------");
    console.log(error);
    console.log(completed);
    console.log(statistic);
    console.log("-------------");
  }
);
}
min2();
// imageMin();
